<?php
class set_menu extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('mset_menu');
	}
	
	function index()
	{
		$token = $this->session->userdata('token');
		if($token){
			$data['results'] = $this->mset_menu->getList();
			$this->load->view('set_menu/list',$data);
		}else{
			redirect('admin');
		}
	}
    
	function add(){
		$data['mode'] = "Create";
		$data['action'] = "save";
		$data['induk'] = $this->mset_menu->getMasterList();
		$data['set'] = $this->mset_menu->getList();
		$this->load->view('set_menu/form',$data);
	}
	
	function edit($id_menu){
		$data['detail'] = $this->mset_menu->detail($id_menu);
		$data['mode'] = "Edit";
		$data['action'] = "update";
		$data['induk'] = $this->mset_menu->getMasterList();
		$data['set'] = $this->mset_menu->getList();
		$this->load->view('set_menu/form',$data);
	}
	
	function save()
	{
		$id_menu = $this->input->post('id_menu');
		$nama_menu = $this->input->post('nama_menu');
		$urut_menu = $this->input->post('urut_menu');
		$enable_menu = $this->input->post('enable_menu');
		$master_menu = $this->input->post('master_menu');
		$jenis_menu = $this->input->post('jenis_menu');
		$group_menu = $this->input->post('group_menu');
		
		if($group_menu == 1 ){
			$induk_menu = $this->input->post('induk_menu');
		}else{
			$induk_menu = 0 ;
		}
		
		$submit = $this->input->post('submit');	
		if ($submit)
		{
			$this->mset_menu->setData($id_menu,$nama_menu,$urut_menu,$enable_menu,$master_menu,$jenis_menu,$group_menu,$induk_menu);
			$this->mset_menu->create();
			$this->session->set_flashdata('success', true);
			redirect('set_menu');
		}
	}
	
	function update()
	{
		$id_menu = $this->input->post('id_menu');
		$nama_menu = $this->input->post('nama_menu');
		$urut_menu = $this->input->post('urut_menu');
		$enable_menu = $this->input->post('enable_menu');
		$master_menu = $this->input->post('master_menu');
		$jenis_menu = $this->input->post('jenis_menu');
		$group_menu = $this->input->post('group_menu');
		
		if($group_menu == 1 ){
			$induk_menu = $this->input->post('induk_menu');
		}else{
			$induk_menu = 0 ;
		}
		
		$submit = $this->input->post('submit');	
		if ($submit)
		{
			$this->mset_menu->setData($id_menu,$nama_menu,$urut_menu,$enable_menu,$master_menu,$jenis_menu,$group_menu,$induk_menu);
			$this->mset_menu->update($id_menu);
			$this->session->set_flashdata('success', true);
			redirect('set_menu');
		}
	}
	
	function delete($id_menu)
	{
		if ($this->mset_menu->remove($id_menu)){
			$this->session->set_flashdata('delete', true);
			redirect('set_menu','refresh');
		}	
	}	
}
?>